package com.fary;

import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigChangeListener;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * 分布式apollo配置中心监听   ed84af8a11b6e33ee180eab7e53cdbf9
 */
@Component
@Slf4j
public class MyCommandLineRunner implements CommandLineRunner {
	@ApolloConfig
	private Config config;

	@Autowired
	private DocumentationConfig documentationConfig;

	@Override
	public void run(String... args) throws Exception {
		// 开启监听，配置文件发生改变需要更改
		config.addChangeListener(new ConfigChangeListener() {
			@Override
			public void onChange(ConfigChangeEvent changeEvent) {
				log.info("####分布式配置中心监听#####" + changeEvent.changedKeys().toString());
				documentationConfig.get();
			}
		});
	}

}